// pages/mine/help_record/help_record.js
import util from '../../../utils/util'
import {
  HelpList,
  UpAssess
} from '../../../config/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    member:'',
    data: [],
    isEmpty: false,
    items: [{
        value: 3,
        name: '非常满意',
        checked: 'true'
      },
      {
        value: 2,
        name: '满意'
      },
      {
        value: 1,
        name: '不满意'
      }
    ],
    level:3, // 默认非常满意
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let member = wx.getStorageSync("member");
    this.setData({
      member
    })

    console.log(member)
    console.log('code:', member.code);
    console.log('uid:', member.id);

    // let params={
    //      code:"lt1",
    //      uid:39,
    //      t:0
    // };//测试数据

    this.getList()
  },

   getList(){
     let that = this;
     let params = {
       code: that.data.member.code,
       page: 1,
       limit: 1000
     };
     util.apiRequest(HelpList, params, null).then(r => {
       console.log('求助记录', r.data.data.data);
       if (r.data.data.data.length == 0) {
         that.setData({
           isEmpty: true
         });
       } else {
         that.setData({
           data: r.data.data.data,
         });
       }
     });
   },

  radioChange(e) {
    console.log('radio携带value值为：', e.detail.value)

    const items = this.data.items
    for (let i = 0, len = items.length; i < len; ++i) {
      console.log('每一个item',items[i].value)
      items[i].checked = items[i].value == e.detail.value
    }

    console.log('复制后',items)

    this.setData({
      level: e.detail.value,
      items
    })
  },

  submitPj(e){
    let that =this;
    console.log('66id:',e.currentTarget.dataset.id)
    let params={
      type:2,
      level:that.data.level,
      eid: e.currentTarget.dataset.id,
      uid: this.data.member.id,
      u_name: this.data.member.name,
      vollege_id: this.data.member.vollege_id,
      town_id: this.data.member.town_id,
    }
    util.apiRequest(UpAssess,params).then( r => {
      console.log('评价后',r)
      if(r.data.code==1){
        that.getList(); // 重新渲染列表数据
        wx.showToast({
          icon:'none',
          title: '评价成功',
        })
      }
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})